﻿using DreamStore.WebShop.Models;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace DreamStore.WebShop.Drivers
{
    [UsedImplicitly]
    public class CustomerDiscountProgramDriver : ContentPartDriver<CustomerDiscountProgramPart>
    {
        private const string TemplateName = "Parts/CustomerDiscountProgram";
        protected override string Prefix
        {
            get { return "CustomerDiscountProgram"; }
        }

        protected override DriverResult Display(CustomerDiscountProgramPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_CustomerDiscountProgram", () => shapeHelper.Parts_CustomerDiscountProgram(Part: part));
        }

        //GET
        protected override DriverResult Editor(CustomerDiscountProgramPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_CustomerDiscountProgram_Edit", () => shapeHelper.EditorTemplate(
                TemplateName: TemplateName,
                Model: part,
                Prefix: Prefix));
        }

        //POST
        protected override DriverResult Editor(CustomerDiscountProgramPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}